package com.rs.controller;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.FlowLayout;
import javax.swing.SpringLayout;
import javax.swing.JMenu;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JMenuItem;
import javax.swing.event.MenuDragMouseListener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.rs.model.ZhLeanprogress;
import com.rs.model.ZhPosition;
import com.rs.model.ZhUser;
import com.rs.service.PublicUserMethodsService;
import com.rs.util.ImagePanel;
import com.rs.util.SpringContextUtils;

import javax.swing.event.MenuDragMouseEvent;
import javax.swing.JMenuBar;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JLabel;
import java.awt.Toolkit;
import java.awt.Font;
import javax.swing.ImageIcon;
import java.awt.CardLayout;
import javax.swing.UIManager;
import javax.swing.JDesktopPane;
import javax.swing.JTabbedPane;
import javax.swing.SpinnerDateModel;
import javax.swing.JPopupMenu;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * @author zjw
 *
 */

public class Menu extends JFrame {
	

	private JPanel contentPane;
	
	private JDesktopPane desktopPane;
	
	private JDesktopPane desktopPane_1;
	
	private JMenu menu;
	
	private PublicUserMethodsService pum  = SpringContextUtils.getBean(PublicUserMethodsService.class);
	
	Map<String, Integer> mapPo=new HashMap<>();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Menu frame = new Menu(null);
					frame.setVisible(true);
					frame.setLocationRelativeTo(null);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Menu(final ZhUser user) {
		setBackground(SystemColor.control);
		setResizable(false);
		setTitle("\u4E2D\u79BE\u6559\u80B2\u7BA1\u7406\u7CFB\u7EDF");
		setIconImage(Toolkit.getDefaultToolkit().getImage(Menu.class.getResource("/images/logo1.png")));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		int x = (int)(toolkit.getScreenSize().getWidth()-1100)/2;
		int y = (int)(toolkit.getScreenSize().getHeight()-800)/2;
		setBounds(x, y, 1100, 800);
		JMenuBar menuBar_1 = new JMenuBar();
		setJMenuBar(menuBar_1);
		
		
		
		
		JMenu men_user = new JMenu("\u4EBA\u5458\u7BA1\u7406");
		menuBar_1.add(men_user);
		men_user.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_user.setBackground(Color.WHITE);
		men_user.setIcon(new ImageIcon(Menu.class.getResource("/images/\u4EBA\u5458.png")));
		
		
		menu = new JMenu("用户管理");
		men_user.add(menu);
		
		JMenuItem menuItem_1 = new JMenuItem("用户添加");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AddTeacher addTeacher = new AddTeacher();
				addTeacher.setVisible(true);
				desktopPane_1.add(addTeacher);
			}
		});
		menu.add(menuItem_1);
		setTheValue();
		
		JMenu men_attendance = new JMenu("\u8003\u52E4\u7BA1\u7406");
		menuBar_1.add(men_attendance);
		men_attendance.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_attendance.setIcon(new ImageIcon(Menu.class.getResource("/images/\u8003\u52E4.png")));
		
		JMenu menu_atten_tea = new JMenu("工作人员考勤管理");
		men_attendance.add(menu_atten_tea);
		
		JMenuItem menuit_atten_tealist = new JMenuItem("工作人员考勤管理列表");
		menuit_atten_tealist.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AttendanceList attendanceList = new AttendanceList();
				attendanceList.setVisible(true);
				desktopPane_1.add(attendanceList);
			}
		});
		menu_atten_tea.add(menuit_atten_tealist);
		
		
		JMenu menu_atten_stu = new JMenu("学生考勤管理");
		men_attendance.add(menu_atten_stu);
		
		JMenuItem menuit_atten_stulist = new JMenuItem("学生考勤管理列表");
		menuit_atten_stulist.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StudentsAttendanceList studentsAttendanceList = new StudentsAttendanceList();
				studentsAttendanceList.setVisible(true);
				desktopPane_1.add(studentsAttendanceList);
			}
		});	
		menu_atten_stu.add(menuit_atten_stulist);
		
		
		
		JMenu men_workLog = new JMenu("\u5DE5\u4F5C\u65E5\u5FD7\u7BA1\u7406");
		menuBar_1.add(men_workLog);
		men_workLog.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_workLog.setIcon(new ImageIcon(Menu.class.getResource("/images/\u5DE5\u4F5C\u65E5\u5FD7.png")));
		
		JMenuItem menuItem_2 = new JMenuItem("工作日志列表");
		menuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TeacherWorkLog teacherWorkLog = new TeacherWorkLog();
				teacherWorkLog.setVisible(true);
				desktopPane_1.add(teacherWorkLog);
			}
		});
		men_workLog.add(menuItem_2);
		
		JMenu men_classes = new JMenu("\u73ED\u7EA7\u7BA1\u7406");
		menuBar_1.add(men_classes);
		men_classes.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_classes.setIcon(new ImageIcon(Menu.class.getResource("/images/\u73ED\u7EA7.png")));
		
		JMenuItem menu_1 = new JMenuItem("添加班级");
		menu_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			 new ClassInfo(desktopPane_1).setVisible(true);
			}
		});
		men_classes.add(menu_1);
		
		
		JMenuItem menu_2 = new JMenuItem("班级列表");
		menu_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SelectClass clas =new SelectClass(desktopPane_1);
				clas.setVisible(true);
				desktopPane_1.add(clas);
			}
		});
		men_classes.add(menu_2);
		
		JMenuItem menuItem = new JMenuItem("就业班级信息");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SelectEmployment se = new SelectEmployment(desktopPane_1);
				se.setVisible(true);
				desktopPane_1.add(se);
			}
		});
		men_classes.add(menuItem);
		
		JMenuItem menuItem_21 = new JMenuItem("添加就业班级");
		menuItem_21.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new EmploymentInfo().setVisible(true);
			}
		});
		men_classes.add(menuItem_21);
		
		
		JMenu men_goods = new JMenu("\u8BBE\u5907\u7BA1\u7406");
		menuBar_1.add(men_goods);
		men_goods.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_goods.setIcon(new ImageIcon(Menu.class.getResource("/images/\u9ED8\u8BA4.png")));
		
		JMenuItem menuit_goodslist = new JMenuItem("设备列表");
		menuit_goodslist.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GoodsList goodsList = new GoodsList(desktopPane_1);
				goodsList.setVisible(true);
				desktopPane_1.add(goodsList);
			}
		});
		men_goods.add(menuit_goodslist);
		
		
		JMenu men_department = new JMenu("\u90E8\u95E8\u7BA1\u7406");
		menuBar_1.add(men_department);
		men_department.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_department.setIcon(new ImageIcon(Menu.class.getResource("/images/\u90E8\u95E8.png")));
		
		JMenuItem menuItem_3 = new JMenuItem("部门职务管理");
		menuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ZhDepartmentList zDepartment = new ZhDepartmentList(desktopPane_1);
				zDepartment.setVisible(true);
				desktopPane_1.add(zDepartment);
//				new ZhDepartment().setVisible(true);
			}
		});
		men_department.add(menuItem_3);
		
		
		JMenu men_leanprogress = new JMenu("教学大纲管理");
		menuBar_1.add(men_leanprogress);
		men_leanprogress.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_leanprogress.setIcon(new ImageIcon(Menu.class.getResource("/images/\u6559\u5B66\u8FDB\u5EA6.png")));
		
		JMenuItem menuItem1 = new JMenuItem("教学大纲列表");
		menuItem1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ZhLeanprogressList zhLeanprogressList = new ZhLeanprogressList(desktopPane_1);
				zhLeanprogressList.setVisible(true);
				desktopPane_1.add(zhLeanprogressList);
			}
		});
		men_leanprogress.add(menuItem1);
		
		
		JMenu men_studentDaily = new JMenu("\u5B66\u751F\u65E5\u5E38\u7BA1\u7406");
		menuBar_1.add(men_studentDaily);
		men_studentDaily.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_studentDaily.setIcon(new ImageIcon(Menu.class.getResource("/images/\u5B66\u751F\u65E5\u5E38.png")));
		
		JMenuItem menit_gradelist = new JMenuItem("学生成绩列表");
		menit_gradelist.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GradeList gradelist = new GradeList(desktopPane_1);
				gradelist.setVisible(true);
				desktopPane_1.add(gradelist);
			}
		});
		men_studentDaily.add(menit_gradelist);
		
		
		
		/*
		 * JMenu men_job = new JMenu("\u5C31\u4E1A\u7BA1\u7406");
		 * menuBar_1.add(men_job); men_job.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		 * men_job.setIcon(new
		 * ImageIcon(Menu.class.getResource("/images/\u5C31\u4E1A.png")));
		 */
		
		JMenu men_check = new JMenu("\u5BA1\u6838\u7BA1\u7406");
		menuBar_1.add(men_check);
		men_check.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_check.setIcon(new ImageIcon(Menu.class.getResource("/images/\u5BA1\u6838.png")));
		
		JMenuItem menuItem_4 = new JMenuItem("出差审核管理");
		menuItem_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ZhOnbusinessList zhOnbusiness = new ZhOnbusinessList(desktopPane_1,user.getuId());
				zhOnbusiness.setVisible(true);
				desktopPane_1.add(zhOnbusiness);
			}
		});
		men_check.add(menuItem_4);
		
		JMenuItem menuItem_31 = new JMenuItem("人员审核");
		  menuItem_31.addActionListener(new ActionListener() {
		   public void actionPerformed(ActionEvent e) {
		    SelectUserAudit ss = new SelectUserAudit(user);
		    ss.setVisible(true);
		    desktopPane_1.add(ss);
		   }
		  });
		  men_check.add(menuItem_31);
		
		JMenuItem menuItem_5 = new JMenuItem("班级毕业审核");
		menuItem_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ClassList classList = new ClassList(desktopPane_1,user.getuId());
				classList.setVisible(true);
				desktopPane_1.add(classList);
			}
		});
		men_check.add(menuItem_5);
		
		JMenuItem menuItem_6 = new JMenuItem("加班审核");
		  menuItem_6.addActionListener(new ActionListener() {
		   public void actionPerformed(ActionEvent e) {
		    SelectOverTime ov = new SelectOverTime(user);
		    ov.setVisible(true);
		    desktopPane_1.add(ov);
		   }
		  });
		  men_check.add(menuItem_6);
		  
			JMenuItem menit_goout = new JMenuItem("外出审核列表");
			menit_goout.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					GoOutList gooutlist = new GoOutList(desktopPane_1,user);
					gooutlist.setVisible(true);
					desktopPane_1.add(gooutlist);
				}
			});
			
			men_check.add(menit_goout);
			
			JMenuItem menit_askfor = new JMenuItem("请假审核列表");
			menit_askfor.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					AskForList askforlist = new AskForList(desktopPane_1,user);
					askforlist.setVisible(true);
					desktopPane_1.add(askforlist);
				}
			});
			men_check.add(menit_askfor);
			
			JMenuItem menuItem_7 = new JMenuItem("物品领用审核");
			  menuItem_7.addActionListener(new ActionListener() {
			   public void actionPerformed(ActionEvent e) {
			    SelectItemsRecipients it = new SelectItemsRecipients(user);
			    it.setVisible(true);
			    desktopPane_1.add(it);
			   }
			  });
			  men_check.add(menuItem_7);
			  
			  JMenuItem menit_reimburse = new JMenuItem("报销审核列表");
				menit_reimburse.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						ReimburseList reimburse = new ReimburseList(desktopPane_1, user);
						reimburse.setVisible(true);
						desktopPane_1.add(reimburse);
					}
				});
				men_check.add(menit_reimburse);
		
		
		desktopPane = new JDesktopPane();
	
		
		ImagePanel imagePanel = new ImagePanel(1100,800,"timg.jpg");
		imagePanel.setForeground(Color.LIGHT_GRAY);
		setContentPane(desktopPane);
		desktopPane.setLayout(new BorderLayout(0, 0));
		getContentPane().add(imagePanel);
		
		contentPane = new JPanel();

		this.getContentPane().setBackground(SystemColor.window);
		 imagePanel.setLayout(new BorderLayout(0, 0));
		 
		 desktopPane_1 = new JDesktopPane();
		 imagePanel.add(desktopPane_1, BorderLayout.CENTER);
		 desktopPane_1.setOpaque(false);
		 desktopPane_1.setBackground(null);
		
		
		this.getContentPane().setVisible(true);
		contentPane.setLayout(new BorderLayout(0, 0));
		
	}

	private static void addPopup(Component component, final JPopupMenu popup) {
		component.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			private void showMenu(MouseEvent e) {
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}
	
	//查询所有职无
	public void setTheValue(){
		List<ZhPosition> listPo = pum.selectPoAll();
		for(ZhPosition list:listPo){
			final String name=list.getPoName();
			JMenuItem menuItem = new JMenuItem(list.getPoName()+"查询");
			menuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					SelectUser users=new SelectUser(mapPo.get(name),desktopPane_1);
					users.setVisible(true);
					desktopPane_1.add(users);
				}
			});
			menu.add(menuItem);
			mapPo.put(list.getPoName(),list.getPoId());
		}
		
	}
}
